package com.sorting;

/**
 * Created by nkrivko on 12.01.2015.
 */
public class ShellSort implements Sort {
    public void sort(char[] s) {
        int length = s.length;
        int h = 1;
        while (h < length / 3) {
            h = 3 * h + 1;//1,4,13,40,121,364,1093
        }
        while (h >= 1) {
            for (int i = h; i < length; i++) {
                for (int j = i; j >= h && s[j] < s[j - h]; j -= h) {
                    Util.exchange(s, j, j - h);
                }
            }
            h = h / 3;
        }

        System.out.print("Shellsort: ");
        Util.show(s);}
}
